package com.review.project.service.impl;

import java.security.Security;
import java.util.Date;
import java.util.List;

import com.review.common.utils.SecurityUtils;
import com.review.project.domain.ProjectData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.review.project.mapper.ReviewProjectMapper;
import com.review.project.domain.ReviewProject;
import com.review.project.service.IReviewProjectService;

/**
 * 项目Service业务层处理
 *
 * @author ruoyi
 * @date 2022-03-13
 */
@Service
public class ReviewProjectServiceImpl implements IReviewProjectService
{
    @Autowired
    private ReviewProjectMapper reviewProjectMapper;

    /**
     * 查询项目
     *
     * @param id 项目主键
     * @return 项目
     */
    @Override
    public ReviewProject selectReviewProjectById(Long id)
    {


        return reviewProjectMapper.selectReviewProjectById(id);
    }

    /**
     * 查询项目列表
     *
     * @param reviewProject 项目
     * @return 项目
     */
    @Override
    public List<ReviewProject> selectReviewProjectList(ReviewProject reviewProject)
    {

        reviewProject.setProAuthor(SecurityUtils.getUsername());
        return reviewProjectMapper.selectReviewProjectList(reviewProject);
    }

    /**
     * 新增项目
     *
     * @param reviewProject 项目
     * @return 结果
     */
    @Override
    public int insertReviewProject(ReviewProject reviewProject)
    {
        reviewProject.setProAuthor(SecurityUtils.getUsername());
        reviewProject.setProCreatetime(new Date());
        reviewProject.setUserId(SecurityUtils.getUserId());
        return reviewProjectMapper.insertReviewProject(reviewProject);
    }

    /**
     * 修改项目
     *
     * @param reviewProject 项目
     * @return 结果
     */
    @Override
    public int updateReviewProject(ReviewProject reviewProject)
    {
        return reviewProjectMapper.updateReviewProject(reviewProject);
    }

    /**
     * 批量删除项目
     *
     * @param ids 需要删除的项目主键
     * @return 结果
     */
    @Override
    public int deleteReviewProjectByIds(Long[] ids)
    {
        return reviewProjectMapper.deleteReviewProjectByIds(ids);
    }

    /**
     * 删除项目信息
     *
     * @param id 项目主键
     * @return 结果
     */
    @Override
    public int deleteReviewProjectById(Long id)
    {
        return reviewProjectMapper.deleteReviewProjectById(id);
    }

    @Override
    public List<ReviewProject> getAllList(ReviewProject reviewProject) {
        return reviewProjectMapper.getAllList(reviewProject);
    }

    @Override
    public List<ProjectData> selectTask(ReviewProject reviewProject) {
        reviewProject.setId(SecurityUtils.getUserId());
        return reviewProjectMapper.selectTask(reviewProject);
    }
    @Override
    public List<ProjectData> selectMyScore(ReviewProject reviewProject) {
        reviewProject.setId(SecurityUtils.getUserId());
        return reviewProjectMapper.selectMyScore(reviewProject);
    }
    @Override
    public List<ProjectData> selectAllScore(ReviewProject reviewProject) {
//        reviewProject.setId(SecurityUtils.getUserId());
        return reviewProjectMapper.selectAllScore(reviewProject);
    }
    @Override
    public List<ProjectData> selectProByid(ReviewProject reviewProject,Long groupId) {
        return reviewProjectMapper.selectProByid(reviewProject,groupId);
    }

    @Override
    public ReviewProject selectScore(Long id) {
        Long userId=SecurityUtils.getUserId();
        return reviewProjectMapper.selectScore(id,userId);
    }

    @Override
    public int updateReviewScore(ReviewProject reviewProject) {
        Long userId=SecurityUtils.getUserId();
        return reviewProjectMapper.updateReviewScore(reviewProject,userId);
    }
}
